/* 
 * File:   test_properties.h
 * Author: ferranferri
 *
 * Created on May 15, 2013, 10:37 AM
 */

#ifndef _TEST_Z3D_UTILS_PROPERTIES_H
#define	_TEST_Z3D_UTILS_PROPERTIES_H

#include <gtest/gtest.h>
#include "utils/cuUtils.h"

class Properties_TestFixture : public ::testing::Test {
protected:
    z3d::utils::Properties* _properties;
    std::string _propertiesFile;
public:

    virtual void SetUp() {
#ifdef _WIN32
        _propertiesFile = "../../resources/test/utils/engine.ini";
#else
		_propertiesFile = "../resources/test/utils/engine.ini";
#endif
        _properties = new z3d::utils::Properties(_propertiesFile, true);
    }
    
    virtual void TearDown() {
        delete _properties;
    }
};

TEST_F(Properties_TestFixture, Properties_processFile_when_no_errors_occur_should_return_true)
{
    ASSERT_EQ(_properties->processFile(),true);
}

TEST_F(Properties_TestFixture, Properties_processFile_when_fileName_is_empty_return_false)
{
    _properties->setFileName("");
    ASSERT_EQ(_properties->processFile(), false);
}

TEST_F(Properties_TestFixture, Properties_processFile_when_file_doesnt_exists_return_false)
{
    _properties->setFileName("non-existent.ini");
    ASSERT_EQ(_properties->processFile(), false);
}

TEST_F(Properties_TestFixture, Properties_getPropertyAsString_when_property_exists_return_the_property_value_as_string)
{
    _properties->processFile();
    std::string res = _properties->getPropertyAsString("app_name", "");
    ASSERT_EQ(res , "zeleste Engine test");
}

TEST_F(Properties_TestFixture, Properties_getPropertyAsString_when_property_is_a_path_return_property_of_last_propName)
{
    _properties->processFile();
    ASSERT_EQ(_properties->getPropertyAsString("text_version/major", ""), "0");
}

TEST_F(Properties_TestFixture, Properties_getPropertyAsString_when_property_is_not_castable_to_string_throws_exception)
{
    _properties->processFile();
    ASSERT_THROW(_properties->getPropertyAsString("client_version/major", ""), z3d::core::resourceTypeConversionException);
}

TEST_F(Properties_TestFixture, Properties_getPropertyAsUnsigned_when_property_is_not_castable_to_string_throws_exception)
{
    _properties->processFile();
    ASSERT_EQ( _properties->getPropertyAsUnsigned("client_version/major", 3), 1);
}

TEST_F(Properties_TestFixture, Properties_exists_when_property_exists_return_true)
{
    _properties->processFile();
    ASSERT_TRUE(_properties->exists("existent_property"));
}

TEST_F(Properties_TestFixture, Properties_exists_when_property_not_exists_return_false)
{
    _properties->processFile();
    ASSERT_FALSE(_properties->exists("inexistent_property"));
}
//TEST_F(Properties_TestFixture, Properties_writeAsString_you_can_write_in_root_level)
//{
//    _properties->processFile();
//    if(_properties->writeAsString("prop_to_write"))
//}
#endif	/* _TEST_Z3D_UTILS_PROPERTIES_H */

class BugFixPropertiesSimpleWindow_TestFixture : public ::testing::Test {
protected:
    z3d::utils::Properties* _properties;
    std::string _propertiesFile;
public:

    virtual void SetUp() {
#ifdef _WIN32
        _propertiesFile = "../../resources/programs/simple_window.ini";
#else
		_propertiesFile = "../resources/programs/simple_window.ini";
#endif
        _properties = new z3d::utils::Properties(_propertiesFile, true);
        _properties->processFile();
    }
    
    virtual void TearDown() {
        delete _properties;
    }
};

TEST_F(BugFixPropertiesSimpleWindow_TestFixture, vfs_tag_is_not_correctly_processed) {
    z3d::utils::Properties* prop = _properties->getChild("vfs");
    std::string rootPath = prop->getPropertyAsString("root", "./");
    std::string writePath = prop->getPropertyAsString("writePath", "./tmp/");

}